package ui;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;


import controller.MobilePlanSellAndBillSystem;
import customexceptions.UserAlreadyExistsException;



/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class CreateClientsUI extends javax.swing.JFrame {
	private JTextField jTextFieldClientName;
	private JButton jButtonAccept;
	private JLabel jLabelClientName;
	private JTextField jTextFieldClientLastName;
	private JLabel jLabelClientLastName;
	private JTextField jTextFieldClientDNI;
	private JLabel jLabelClientDNI;
	private JTextField jTextFieldClientAddress;
	private JLabel jLabelClientAddress;
	private JTextField jTextFieldClientEmail;
	private JLabel jLabelClientEmail;
	private MobilePlanSellAndBillSystem system;

	/**
	* Auto-generated main method to display this JFrame
	*/
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				CreateClientsUI inst = new CreateClientsUI();
				inst.setLocationRelativeTo(null);
				inst.setVisible(true);
			}
		});
	}
	public CreateClientsUI(){
		
	}
	public CreateClientsUI(MobilePlanSellAndBillSystem system) {
		super();
		initGUI();
		this.system = system;
	}
	
	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			getContentPane().setLayout(null);
			{
				jTextFieldClientName = new JTextField();
				getContentPane().add(jTextFieldClientName);
				jTextFieldClientName.setBounds(93, 47, 333, 28);
			}
			{
				jLabelClientName = new JLabel();
				getContentPane().add(jLabelClientName);
				jLabelClientName.setText("Name");
				jLabelClientName.setBounds(12, 59, 62, 16);
			}
			{
				jTextFieldClientLastName = new JTextField();
				getContentPane().add(jTextFieldClientLastName);
				jTextFieldClientLastName.setBounds(91, 87, 333, 28);
			}
			{
				jLabelClientLastName = new JLabel();
				getContentPane().add(jLabelClientLastName);
				jLabelClientLastName.setText("Last Name");
				jLabelClientLastName.setBounds(12, 99, 67, 16);
			}	
			{
				jTextFieldClientDNI = new JTextField();
				getContentPane().add(jTextFieldClientDNI);
				jTextFieldClientDNI.setBounds(92, 127, 333, 28);
			}
			{
				jLabelClientDNI = new JLabel();
				getContentPane().add(jLabelClientDNI);
				jLabelClientDNI.setText("ID Number");
				jLabelClientDNI.setBounds(12, 139, 74, 16);
			}
			{
				jTextFieldClientAddress = new JTextField();
				getContentPane().add(jTextFieldClientAddress);
				jTextFieldClientAddress.setBounds(92, 167, 333, 28);
			}
			{
				jLabelClientAddress = new JLabel();
				getContentPane().add(jLabelClientAddress);
				jLabelClientAddress.setText("Address");
				jLabelClientAddress.setBounds(12, 179, 74, 16);
			}
			{
				jTextFieldClientEmail = new JTextField();
				getContentPane().add(jTextFieldClientEmail);
				jTextFieldClientEmail.setBounds(92, 207, 333, 28);
			}
			{
				jLabelClientEmail= new JLabel();
				getContentPane().add(jLabelClientEmail);
				jLabelClientEmail.setText("Email");
				jLabelClientEmail.setBounds(12, 219, 74, 16);
			}	
			{
				jButtonAccept = new JButton();
				getContentPane().add(jButtonAccept);
				jButtonAccept.setText("Create");
				jButtonAccept.setBounds(203, 283, 48, 23);

				jButtonAccept.addActionListener(new ActionListener()
				{
					public void actionPerformed(ActionEvent evt) 
					{
					
							try {
								system.createUser(jTextFieldClientName.getText(), 
										jTextFieldClientLastName.getText(), 
										jTextFieldClientDNI.getText(), 
										jTextFieldClientAddress.getText(),"", 
										jTextFieldClientEmail.getText());
							} catch (UserAlreadyExistsException e) {
								ErrorReportView errorReportView = new ErrorReportView(e.getErrorMessage());
								errorReportView.setVisible(true);
							}

							jTextFieldClientName.setText("");
							jTextFieldClientLastName.setText("");
							jTextFieldClientAddress.setText("");
							jTextFieldClientEmail.setText("");
							jTextFieldClientDNI.setText("");
					}
				});
				
			}//5383217
			/*
					this.dni = dni;
					this.domicilio = domicilio;
					this.email = email;
			 */
			pack();
			this.setSize(510, 417);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
